import static java.lang.Math.*;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: user
 * Date: 2023-11-04
 * Time: 20:17
 */
class Student {
    private String name;
    private int age;

    public static String classRoom;//上课的教室

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getClassRoom() {
        return classRoom;
    }

    public void setClassRoom(String classRoom) {
        this.classRoom = classRoom;
    }

    protected void eat() {
        //static int a = 10;
        System.out.println(this.name +" 正在吃饭！");
        //Student student = new Student("张三",10);
        sleep();
        System.out.println(classRoom);
    }

    public static void sleep() {
        System.out.println( " 正在睡觉！");
    }
}
class TestStatic {


    public static int staticNum = 100;

    public int data1 = 10;

    {
        //构造代码块 || 实例代码块
        System.out.println("实例代码块被执行了....");
        data1 = 1000;//一般情况下  用来初始化 非静态的数据成员
        //staticNum = 1000000;
    }

    static {
        System.out.println("静态代码块被执行了....");
        staticNum = 9999;
    }
    static {
        staticNum = 91999;
    }

    public TestStatic() {
        System.out.println("执行构造方法.....");
    }

    public static void main(String[] args) {
        TestStatic testStatic = new TestStatic();
        //System.out.println(testStatic.data1);
        // System.out.println(TestStatic.staticNum);
    }




    public static void main1(String[] args) {
        TestStatic testStatic = new TestStatic();
        testStatic.staticNum++;

        TestStatic testStatic2 = new TestStatic();

        testStatic2.staticNum++;

        TestStatic testStatic3 = new TestStatic();
        testStatic3.staticNum++;

        TestStatic.staticNum--;

        System.out.println(TestStatic.staticNum);//33 说答案


        {
            int a = 10;
            //定义在方法当中的代码块   不需要条件   永远会被执行
        }

        //System.out.println(a);
    }
}

public class Test {

    public static void main6(String[] args) {
        Student.classRoom ="2-101";

        Student.sleep();

        /*Student student1 = new Student("zhangsan",10);
        student1.sleep();*/

    }



    public static void main5(String[] args) {
        Student student1 = new Student("zhangsan",10);
        student1.classRoom = "2-101";

        Student.classRoom ="2-101";


        Student student2 = new Student("lisi",9);

        Student student3 = new Student("wangmazi",11);

        System.out.println(" ");

    }

    public static void main3(String[] args) {
        double d1 = 12.5;
        double d2 = 12;

        pow(d2,d1);

    }

    public static void main2(String[] args) {
        Student student = new Student("张三",10);
        //student.name = "dsfa"; 实现封装后 类外 就无法 直接拿到这个name字段了
        student.setName("小王");
        System.out.println(student.getName());
        student.eat();

    }
    public static void main1(String[] args) {

        int[] array = {2,2,1,1,4,2,2};
       /* int[] ret = func2(array,99);
        System.out.println(Arrays.toString(ret));

        int ret = func3(array);
        System.out.println(ret);*/

        boolean flg = func4(array);
        System.out.println(flg);
    }

    public static boolean func4(int[] array) {
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            if(array[i] % 2 != 0) {
                count++;
                if(count == 3) {
                    return true;
                }
            }else {
                count = 0;
            }
        }
        return false;
    }

    public static int func3(int[] array) {
        Arrays.sort(array);
        return array[array.length/2];
    }

    public static int[] func2(int[] array,int target) {
        int[] tmp = new int[2];
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j < array.length; j++) {
                if(array[i] + array[j] == target) {
                    tmp[0] = i;
                    tmp[1] = j;
                    return tmp;
                }
            }
        }
        return new int[]{-1,-1};
    }

    public static void func1(int[] array) {
        int i = 0;
        int j = array.length-1;
        while (i < j) {
            while (i < j && array[i] % 2 != 0) {
                i++;
            }
            while (i < j && array[j] % 2 == 0) {
                j--;
            }
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
        }
    }
    public static void transform(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = 2*array[i];
        }
    }
}
